<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <title>Kernel</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <link rel="stylesheet" href="../css/reset.css" type="text/css" media="screen" />
<link rel="stylesheet" href="../css/main.css" type="text/css" media="screen" />
<link rel="stylesheet" href="../css/github.css" type="text/css" media="screen" />
<script src="../js/jquery-1.3.2.min.js" type="text/javascript" charset="utf-8"></script>
<script src="../js/jquery-effect.js" type="text/javascript" charset="utf-8"></script>
<script src="../js/main.js" type="text/javascript" charset="utf-8"></script>
<script src="../js/highlight.pack.js" type="text/javascript" charset="utf-8"></script>

</head>

<body>     
    <div class="banner">
        
            <span>Ruby on Rails v4.0.0</span><br />
        
        <h1>
            <span class="type">Module</span> 
            Kernel 
            
        </h1>
        <ul class="files">
            
            <li><a href="../files/activesupport/lib/active_support/core_ext/kernel/debugger_rb.html">activesupport/lib/active_support/core_ext/kernel/debugger.rb</a></li>
            
            <li><a href="../files/activesupport/lib/active_support/core_ext/kernel/reporting_rb.html">activesupport/lib/active_support/core_ext/kernel/reporting.rb</a></li>
            
            <li><a href="../files/activesupport/lib/active_support/core_ext/kernel/singleton_class_rb.html">activesupport/lib/active_support/core_ext/kernel/singleton_class.rb</a></li>
            
        </ul>
    </div>
    <div id="bodyContent">
        <div id="content">
  


  


  
  


  


  
    <!-- Method ref -->
    <div class="sectiontitle">Methods</div>
    <dl class="methods">
      
        <dt>B</dt>
        <dd>
          <ul>
            
              
              <li>
                <a href="Kernel.html#method-i-breakpoint">breakpoint</a>
              </li>
            
          </ul>
        </dd>
      
        <dt>C</dt>
        <dd>
          <ul>
            
              
              <li>
                <a href="Kernel.html#method-i-capture">capture</a>,
              </li>
            
              
              <li>
                <a href="Kernel.html#method-i-class_eval">class_eval</a>
              </li>
            
          </ul>
        </dd>
      
        <dt>D</dt>
        <dd>
          <ul>
            
              
              <li>
                <a href="Kernel.html#method-i-debugger">debugger</a>
              </li>
            
          </ul>
        </dd>
      
        <dt>E</dt>
        <dd>
          <ul>
            
              
              <li>
                <a href="Kernel.html#method-i-enable_warnings">enable_warnings</a>
              </li>
            
          </ul>
        </dd>
      
        <dt>Q</dt>
        <dd>
          <ul>
            
              
              <li>
                <a href="Kernel.html#method-i-quietly">quietly</a>
              </li>
            
          </ul>
        </dd>
      
        <dt>S</dt>
        <dd>
          <ul>
            
              
              <li>
                <a href="Kernel.html#method-i-silence">silence</a>,
              </li>
            
              
              <li>
                <a href="Kernel.html#method-i-silence_stream">silence_stream</a>,
              </li>
            
              
              <li>
                <a href="Kernel.html#method-i-silence_warnings">silence_warnings</a>,
              </li>
            
              
              <li>
                <a href="Kernel.html#method-i-suppress">suppress</a>
              </li>
            
          </ul>
        </dd>
      
        <dt>W</dt>
        <dd>
          <ul>
            
              
              <li>
                <a href="Kernel.html#method-i-with_warnings">with_warnings</a>
              </li>
            
          </ul>
        </dd>
      
    </dl>
  

  



  

    

    

    


    


    <!-- Methods -->
        
      <div class="sectiontitle">Instance Public methods</div>
      
        <div class="method">
          <div class="title method-title" id="method-i-breakpoint">
            
              <b>breakpoint</b>()
            
            <a href="Kernel.html#method-i-breakpoint" name="method-i-breakpoint" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              
            </div>
          
          
          
          
          
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-capture">
            
              <b>capture</b>(stream)
            
            <a href="Kernel.html#method-i-capture" name="method-i-capture" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              <p>Captures the given stream and returns it:</p>

<pre class="ruby"><span class="ruby-identifier">stream</span> = <span class="ruby-identifier">capture</span>(:<span class="ruby-identifier">stdout</span>) { <span class="ruby-identifier">puts</span> <span class="ruby-string">'notice'</span> }
<span class="ruby-identifier">stream</span> <span class="ruby-comment"># =&gt; &quot;notice\n&quot;</span>

<span class="ruby-identifier">stream</span> = <span class="ruby-identifier">capture</span>(:<span class="ruby-identifier">stderr</span>) { <span class="ruby-identifier">warn</span> <span class="ruby-string">'error'</span> }
<span class="ruby-identifier">stream</span> <span class="ruby-comment"># =&gt; &quot;error\n&quot;</span>
</pre>

<p>even for subprocesses:</p>

<pre class="ruby"><span class="ruby-identifier">stream</span> = <span class="ruby-identifier">capture</span>(:<span class="ruby-identifier">stdout</span>) { <span class="ruby-identifier">system</span>(<span class="ruby-string">'echo notice'</span>) }
<span class="ruby-identifier">stream</span> <span class="ruby-comment"># =&gt; &quot;notice\n&quot;</span>

<span class="ruby-identifier">stream</span> = <span class="ruby-identifier">capture</span>(:<span class="ruby-identifier">stderr</span>) { <span class="ruby-identifier">system</span>(<span class="ruby-string">'echo error 1&gt;&amp;2'</span>) }
<span class="ruby-identifier">stream</span> <span class="ruby-comment"># =&gt; &quot;error\n&quot;</span>
</pre>
            </div>
          
          
          
            <div class="aka">
              Also aliased as: <a href="Kernel.html#method-i-silence">silence</a>
            </div>
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-capture_source')" id="l_method-i-capture_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/70ae89c321444eef42c0c011b522f926250e7acd/activesupport/lib/active_support/core_ext/kernel/reporting.rb#L82" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-capture_source" class="dyn-source">
                <pre><span class="ruby-comment"># File activesupport/lib/active_support/core_ext/kernel/reporting.rb, line 82</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">capture</span>(<span class="ruby-identifier">stream</span>)
  <span class="ruby-identifier">stream</span> = <span class="ruby-identifier">stream</span>.<span class="ruby-identifier">to_s</span>
  <span class="ruby-identifier">captured_stream</span> = <span class="ruby-constant">Tempfile</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">stream</span>)
  <span class="ruby-identifier">stream_io</span> = <span class="ruby-identifier">eval</span>(<span class="ruby-node">&quot;$#{stream}&quot;</span>)
  <span class="ruby-identifier">origin_stream</span> = <span class="ruby-identifier">stream_io</span>.<span class="ruby-identifier">dup</span>
  <span class="ruby-identifier">stream_io</span>.<span class="ruby-identifier">reopen</span>(<span class="ruby-identifier">captured_stream</span>)

  <span class="ruby-keyword">yield</span>

  <span class="ruby-identifier">stream_io</span>.<span class="ruby-identifier">rewind</span>
  <span class="ruby-keyword">return</span> <span class="ruby-identifier">captured_stream</span>.<span class="ruby-identifier">read</span>
<span class="ruby-keyword">ensure</span>
  <span class="ruby-identifier">captured_stream</span>.<span class="ruby-identifier">unlink</span>
  <span class="ruby-identifier">stream_io</span>.<span class="ruby-identifier">reopen</span>(<span class="ruby-identifier">origin_stream</span>)
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-class_eval">
            
              <b>class_eval</b>(*args, &amp;block)
            
            <a href="Kernel.html#method-i-class_eval" name="method-i-class_eval" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              <p><a href="Kernel.html#method-i-class_eval">#class_eval</a> on an object acts
like singleton_class.class_eval.</p>
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-class_eval_source')" id="l_method-i-class_eval_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/a57c6441a829a08d3ca341eecf4f1b4a5e43b909/activesupport/lib/active_support/core_ext/kernel/singleton_class.rb#L3" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-class_eval_source" class="dyn-source">
                <pre><span class="ruby-comment"># File activesupport/lib/active_support/core_ext/kernel/singleton_class.rb, line 3</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">class_eval</span>(*<span class="ruby-identifier">args</span>, &amp;<span class="ruby-identifier">block</span>)
  <span class="ruby-identifier">singleton_class</span>.<span class="ruby-identifier">class_eval</span>(*<span class="ruby-identifier">args</span>, &amp;<span class="ruby-identifier">block</span>)
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-debugger">
            
              <b>debugger</b>()
            
            <a href="Kernel.html#method-i-debugger" name="method-i-debugger" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              <p>Starts a debugging session if the <code>debugger</code> gem has been loaded
(call rails server –debugger to do load it).</p>
            </div>
          
          
          
            <div class="aka">
              Also aliased as: <a href="Kernel.html#method-i-breakpoint">breakpoint</a>
            </div>
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-debugger_source')" id="l_method-i-debugger_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/d6c831c198baee2542a070c62f1608f88fe60e34/activesupport/lib/active_support/core_ext/kernel/debugger.rb#L4" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-debugger_source" class="dyn-source">
                <pre><span class="ruby-comment"># File activesupport/lib/active_support/core_ext/kernel/debugger.rb, line 4</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">debugger</span>
  <span class="ruby-identifier">message</span> = <span class="ruby-string">&quot;\n***** Debugger requested, but was not available (ensure the debugger gem is listed in Gemfile/installed as gem): Start server with --debugger to enable *****\n&quot;</span>
  <span class="ruby-keyword">defined?</span>(<span class="ruby-constant">Rails</span>) <span class="ruby-operator">?</span> <span class="ruby-constant">Rails</span>.<span class="ruby-identifier">logger</span>.<span class="ruby-identifier">info</span>(<span class="ruby-identifier">message</span>) <span class="ruby-operator">:</span> <span class="ruby-identifier">$stderr</span>.<span class="ruby-identifier">puts</span>(<span class="ruby-identifier">message</span>)
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-enable_warnings">
            
              <b>enable_warnings</b>()
            
            <a href="Kernel.html#method-i-enable_warnings" name="method-i-enable_warnings" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              <p>Sets $VERBOSE to <code>true</code> for the duration of the block and back
to its original value afterwards.</p>
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-enable_warnings_source')" id="l_method-i-enable_warnings_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/70ae89c321444eef42c0c011b522f926250e7acd/activesupport/lib/active_support/core_ext/kernel/reporting.rb#L19" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-enable_warnings_source" class="dyn-source">
                <pre><span class="ruby-comment"># File activesupport/lib/active_support/core_ext/kernel/reporting.rb, line 19</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">enable_warnings</span>
  <span class="ruby-identifier">with_warnings</span>(<span class="ruby-keyword">true</span>) { <span class="ruby-keyword">yield</span> }
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-quietly">
            
              <b>quietly</b>()
            
            <a href="Kernel.html#method-i-quietly" name="method-i-quietly" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              <p>Silences both STDOUT and STDERR, even for subprocesses.</p>

<pre>quietly { system 'bundle install' }</pre>
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-quietly_source')" id="l_method-i-quietly_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/70ae89c321444eef42c0c011b522f926250e7acd/activesupport/lib/active_support/core_ext/kernel/reporting.rb#L102" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-quietly_source" class="dyn-source">
                <pre><span class="ruby-comment"># File activesupport/lib/active_support/core_ext/kernel/reporting.rb, line 102</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">quietly</span>
  <span class="ruby-identifier">silence_stream</span>(<span class="ruby-constant">STDOUT</span>) <span class="ruby-keyword">do</span>
    <span class="ruby-identifier">silence_stream</span>(<span class="ruby-constant">STDERR</span>) <span class="ruby-keyword">do</span>
      <span class="ruby-keyword">yield</span>
    <span class="ruby-keyword">end</span>
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-silence">
            
              <b>silence</b>(stream)
            
            <a href="Kernel.html#method-i-silence" name="method-i-silence" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              
            </div>
          
          
          
          
          
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-silence_stream">
            
              <b>silence_stream</b>(stream)
            
            <a href="Kernel.html#method-i-silence_stream" name="method-i-silence_stream" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              <p>Silences any stream for the duration of the block.</p>

<pre>silence_stream(STDOUT) do
  puts 'This will never be seen'
end

puts 'But this will'</pre>
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-silence_stream_source')" id="l_method-i-silence_stream_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/70ae89c321444eef42c0c011b522f926250e7acd/activesupport/lib/active_support/core_ext/kernel/reporting.rb#L44" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-silence_stream_source" class="dyn-source">
                <pre><span class="ruby-comment"># File activesupport/lib/active_support/core_ext/kernel/reporting.rb, line 44</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">silence_stream</span>(<span class="ruby-identifier">stream</span>)
  <span class="ruby-identifier">old_stream</span> = <span class="ruby-identifier">stream</span>.<span class="ruby-identifier">dup</span>
  <span class="ruby-identifier">stream</span>.<span class="ruby-identifier">reopen</span>(<span class="ruby-constant">RbConfig</span><span class="ruby-operator">::</span><span class="ruby-constant">CONFIG</span>[<span class="ruby-string">'host_os'</span>] <span class="ruby-operator">=~</span> <span class="ruby-regexp">/mswin|mingw/</span> <span class="ruby-operator">?</span> <span class="ruby-string">'NUL:'</span> <span class="ruby-operator">:</span> <span class="ruby-string">'/dev/null'</span>)
  <span class="ruby-identifier">stream</span>.<span class="ruby-identifier">sync</span> = <span class="ruby-keyword">true</span>
  <span class="ruby-keyword">yield</span>
<span class="ruby-keyword">ensure</span>
  <span class="ruby-identifier">stream</span>.<span class="ruby-identifier">reopen</span>(<span class="ruby-identifier">old_stream</span>)
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-silence_warnings">
            
              <b>silence_warnings</b>()
            
            <a href="Kernel.html#method-i-silence_warnings" name="method-i-silence_warnings" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              <p>Sets $VERBOSE to nil for the duration of the block and back to its original
value afterwards.</p>

<pre>silence_warnings do
  value = noisy_call # no warning voiced
end

noisy_call # warning voiced</pre>
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-silence_warnings_source')" id="l_method-i-silence_warnings_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/70ae89c321444eef42c0c011b522f926250e7acd/activesupport/lib/active_support/core_ext/kernel/reporting.rb#L13" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-silence_warnings_source" class="dyn-source">
                <pre><span class="ruby-comment"># File activesupport/lib/active_support/core_ext/kernel/reporting.rb, line 13</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">silence_warnings</span>
  <span class="ruby-identifier">with_warnings</span>(<span class="ruby-keyword">nil</span>) { <span class="ruby-keyword">yield</span> }
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-suppress">
            
              <b>suppress</b>(*exception_classes)
            
            <a href="Kernel.html#method-i-suppress" name="method-i-suppress" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              <p>Blocks and ignores any exception passed as argument if raised within the
block.</p>

<pre>suppress(ZeroDivisionError) do
  1/0
  puts 'This code is NOT reached'
end

puts 'This code gets executed and nothing related to ZeroDivisionError was seen'</pre>
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-suppress_source')" id="l_method-i-suppress_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/70ae89c321444eef42c0c011b522f926250e7acd/activesupport/lib/active_support/core_ext/kernel/reporting.rb#L61" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-suppress_source" class="dyn-source">
                <pre><span class="ruby-comment"># File activesupport/lib/active_support/core_ext/kernel/reporting.rb, line 61</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">suppress</span>(*<span class="ruby-identifier">exception_classes</span>)
  <span class="ruby-keyword">yield</span>
<span class="ruby-keyword">rescue</span> <span class="ruby-constant">Exception</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">e</span>
  <span class="ruby-identifier">raise</span> <span class="ruby-keyword">unless</span> <span class="ruby-identifier">exception_classes</span>.<span class="ruby-identifier">any?</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">cls</span><span class="ruby-operator">|</span> <span class="ruby-identifier">e</span>.<span class="ruby-identifier">kind_of?</span>(<span class="ruby-identifier">cls</span>) }
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
        
        <div class="method">
          <div class="title method-title" id="method-i-with_warnings">
            
              <b>with_warnings</b>(flag)
            
            <a href="Kernel.html#method-i-with_warnings" name="method-i-with_warnings" class="permalink">Link</a>
          </div>
          
          
            <div class="description">
              <p>Sets $VERBOSE for the duration of the block and back to its original value
afterwards.</p>
            </div>
          
          
          
          
          
            
            <div class="sourcecode">
              
              <p class="source-link">
                Source: 
                <a href="javascript:toggleSource('method-i-with_warnings_source')" id="l_method-i-with_warnings_source">show</a>
                
                  | <a href="https://github.com/rails/rails/blob/70ae89c321444eef42c0c011b522f926250e7acd/activesupport/lib/active_support/core_ext/kernel/reporting.rb#L25" target="_blank" class="github_url">on GitHub</a>
                
              </p>
              <div id="method-i-with_warnings_source" class="dyn-source">
                <pre><span class="ruby-comment"># File activesupport/lib/active_support/core_ext/kernel/reporting.rb, line 25</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">with_warnings</span>(<span class="ruby-identifier">flag</span>)
  <span class="ruby-identifier">old_verbose</span>, <span class="ruby-identifier">$VERBOSE</span> = <span class="ruby-identifier">$VERBOSE</span>, <span class="ruby-identifier">flag</span>
  <span class="ruby-keyword">yield</span>
<span class="ruby-keyword">ensure</span>
  <span class="ruby-identifier">$VERBOSE</span> = <span class="ruby-identifier">old_verbose</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
            
          </div>
                    </div>

    </div>
  </body>
</html>    